package com.xiaoma.tpo.webservice;

import com.xiaoma.tpo.domain.LiveList;
import com.xiaoma.tpo.dto.LiveListDto;
import com.xiaoma.tpo.service.LiveListService;
import com.xiaoma.tpo.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Owner on 2015/5/15.
 */
@Controller
@RequestMapping("/service/live")
public class LiveListWs {
    @Autowired
    private LiveListService liveListService;

    @RequestMapping(value = "/list" ,method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> getLiveList(int page,int rows){
        Map<String ,Object> result = new HashMap<String,Object>();
        Pager pager = liveListService.getList(page,rows);
        result.put("rows",pager.getList());
        result.put("total",pager.getTotalCount());
        return result;
    }

    @RequestMapping(value = "/add" ,method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> addLive(LiveListDto ll){
        Map<String ,Object> result = new HashMap<String,Object>();
        Boolean flag = liveListService.addLive(ll);
        result.put("status",flag);
        return result;
    }

    @RequestMapping(value = "/edit" ,method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> editLive(LiveListDto ll){
        Map<String ,Object> result = new HashMap<String,Object>();
        Boolean flag = liveListService.editLive(ll);
        result.put("status",flag);
        return result;
    }


    @RequestMapping(value = "/get" ,method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> getCurrentLive(){
        Map<String ,Object> result = new HashMap<String,Object>();
        LiveList ll = liveListService.getCurrentLive();
        result.put("live",ll);
        result.put("status",1);
        return result;
    }
}
